/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package com.googlecode.mailnet.emf.netmodel.impl;

import java.util.Collection;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;
import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.impl.EObjectImpl;
import org.eclipse.emf.ecore.util.EObjectContainmentEList;
import org.eclipse.emf.ecore.util.InternalEList;

import com.googlecode.mailnet.emf.netmodel.DistributionModel;
import com.googlecode.mailnet.emf.netmodel.LinkModel;
import com.googlecode.mailnet.emf.netmodel.MessageFlowModel;
import com.googlecode.mailnet.emf.netmodel.NetmodelPackage;
import com.googlecode.mailnet.emf.netmodel.NetworkConfigurationModel;
import com.googlecode.mailnet.emf.netmodel.NodeModel;
import com.googlecode.mailnet.emf.netmodel.QueueingConfigurationModel;
import com.googlecode.mailnet.emf.netmodel.simulation.SimulationContext;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Network Configuration Model</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link com.googlecode.mailnet.emf.netmodel.impl.NetworkConfigurationModelImpl#getNodes <em>Nodes</em>}</li>
 *   <li>{@link com.googlecode.mailnet.emf.netmodel.impl.NetworkConfigurationModelImpl#getLinks <em>Links</em>}</li>
 *   <li>{@link com.googlecode.mailnet.emf.netmodel.impl.NetworkConfigurationModelImpl#getDistributions <em>Distributions</em>}</li>
 *   <li>{@link com.googlecode.mailnet.emf.netmodel.impl.NetworkConfigurationModelImpl#getQueueConfiguration <em>Queue Configuration</em>}</li>
 *   <li>{@link com.googlecode.mailnet.emf.netmodel.impl.NetworkConfigurationModelImpl#getMessageFlows <em>Message Flows</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class NetworkConfigurationModelImpl extends EObjectImpl implements NetworkConfigurationModel {

	/**
	 * The cached value of the '{@link #getNodes() <em>Nodes</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getNodes()
	 * @generated
	 * @ordered
	 */
	protected EList<NodeModel> nodes;

	/**
	 * The cached value of the '{@link #getLinks() <em>Links</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getLinks()
	 * @generated
	 * @ordered
	 */
	protected EList<LinkModel> links;

	/**
	 * The cached value of the '{@link #getDistributions() <em>Distributions</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getDistributions()
	 * @generated
	 * @ordered
	 */
	protected EList<DistributionModel> distributions;

	/**
	 * The cached value of the '{@link #getQueueConfiguration() <em>Queue Configuration</em>}' containment reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getQueueConfiguration()
	 * @generated
	 * @ordered
	 */
	protected QueueingConfigurationModel queueConfiguration;

	/**
	 * The cached value of the '{@link #getMessageFlows() <em>Message Flows</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getMessageFlows()
	 * @generated
	 * @ordered
	 */
	protected EList<MessageFlowModel> messageFlows;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected NetworkConfigurationModelImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return NetmodelPackage.Literals.NETWORK_CONFIGURATION_MODEL;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<NodeModel> getNodes() {
		if (nodes == null) {
			nodes = new EObjectContainmentEList<NodeModel>(NodeModel.class, this, NetmodelPackage.NETWORK_CONFIGURATION_MODEL__NODES);
		}
		return nodes;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<LinkModel> getLinks() {
		if (links == null) {
			links = new EObjectContainmentEList<LinkModel>(LinkModel.class, this, NetmodelPackage.NETWORK_CONFIGURATION_MODEL__LINKS);
		}
		return links;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<DistributionModel> getDistributions() {
		if (distributions == null) {
			distributions = new EObjectContainmentEList<DistributionModel>(DistributionModel.class, this, NetmodelPackage.NETWORK_CONFIGURATION_MODEL__DISTRIBUTIONS);
		}
		return distributions;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public QueueingConfigurationModel getQueueConfiguration() {
		return queueConfiguration;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetQueueConfiguration(QueueingConfigurationModel newQueueConfiguration, NotificationChain msgs) {
		QueueingConfigurationModel oldQueueConfiguration = queueConfiguration;
		queueConfiguration = newQueueConfiguration;
		if (eNotificationRequired()) {
			ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, NetmodelPackage.NETWORK_CONFIGURATION_MODEL__QUEUE_CONFIGURATION, oldQueueConfiguration, newQueueConfiguration);
			if (msgs == null) msgs = notification; else msgs.add(notification);
		}
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setQueueConfiguration(QueueingConfigurationModel newQueueConfiguration) {
		if (newQueueConfiguration != queueConfiguration) {
			NotificationChain msgs = null;
			if (queueConfiguration != null)
				msgs = ((InternalEObject)queueConfiguration).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - NetmodelPackage.NETWORK_CONFIGURATION_MODEL__QUEUE_CONFIGURATION, null, msgs);
			if (newQueueConfiguration != null)
				msgs = ((InternalEObject)newQueueConfiguration).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - NetmodelPackage.NETWORK_CONFIGURATION_MODEL__QUEUE_CONFIGURATION, null, msgs);
			msgs = basicSetQueueConfiguration(newQueueConfiguration, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, NetmodelPackage.NETWORK_CONFIGURATION_MODEL__QUEUE_CONFIGURATION, newQueueConfiguration, newQueueConfiguration));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<MessageFlowModel> getMessageFlows() {
		if (messageFlows == null) {
			messageFlows = new EObjectContainmentEList<MessageFlowModel>(MessageFlowModel.class, this, NetmodelPackage.NETWORK_CONFIGURATION_MODEL__MESSAGE_FLOWS);
		}
		return messageFlows;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case NetmodelPackage.NETWORK_CONFIGURATION_MODEL__NODES:
				return ((InternalEList<?>)getNodes()).basicRemove(otherEnd, msgs);
			case NetmodelPackage.NETWORK_CONFIGURATION_MODEL__LINKS:
				return ((InternalEList<?>)getLinks()).basicRemove(otherEnd, msgs);
			case NetmodelPackage.NETWORK_CONFIGURATION_MODEL__DISTRIBUTIONS:
				return ((InternalEList<?>)getDistributions()).basicRemove(otherEnd, msgs);
			case NetmodelPackage.NETWORK_CONFIGURATION_MODEL__QUEUE_CONFIGURATION:
				return basicSetQueueConfiguration(null, msgs);
			case NetmodelPackage.NETWORK_CONFIGURATION_MODEL__MESSAGE_FLOWS:
				return ((InternalEList<?>)getMessageFlows()).basicRemove(otherEnd, msgs);
		}
		return super.eInverseRemove(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case NetmodelPackage.NETWORK_CONFIGURATION_MODEL__NODES:
				return getNodes();
			case NetmodelPackage.NETWORK_CONFIGURATION_MODEL__LINKS:
				return getLinks();
			case NetmodelPackage.NETWORK_CONFIGURATION_MODEL__DISTRIBUTIONS:
				return getDistributions();
			case NetmodelPackage.NETWORK_CONFIGURATION_MODEL__QUEUE_CONFIGURATION:
				return getQueueConfiguration();
			case NetmodelPackage.NETWORK_CONFIGURATION_MODEL__MESSAGE_FLOWS:
				return getMessageFlows();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@SuppressWarnings("unchecked")
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case NetmodelPackage.NETWORK_CONFIGURATION_MODEL__NODES:
				getNodes().clear();
				getNodes().addAll((Collection<? extends NodeModel>)newValue);
				return;
			case NetmodelPackage.NETWORK_CONFIGURATION_MODEL__LINKS:
				getLinks().clear();
				getLinks().addAll((Collection<? extends LinkModel>)newValue);
				return;
			case NetmodelPackage.NETWORK_CONFIGURATION_MODEL__DISTRIBUTIONS:
				getDistributions().clear();
				getDistributions().addAll((Collection<? extends DistributionModel>)newValue);
				return;
			case NetmodelPackage.NETWORK_CONFIGURATION_MODEL__QUEUE_CONFIGURATION:
				setQueueConfiguration((QueueingConfigurationModel)newValue);
				return;
			case NetmodelPackage.NETWORK_CONFIGURATION_MODEL__MESSAGE_FLOWS:
				getMessageFlows().clear();
				getMessageFlows().addAll((Collection<? extends MessageFlowModel>)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case NetmodelPackage.NETWORK_CONFIGURATION_MODEL__NODES:
				getNodes().clear();
				return;
			case NetmodelPackage.NETWORK_CONFIGURATION_MODEL__LINKS:
				getLinks().clear();
				return;
			case NetmodelPackage.NETWORK_CONFIGURATION_MODEL__DISTRIBUTIONS:
				getDistributions().clear();
				return;
			case NetmodelPackage.NETWORK_CONFIGURATION_MODEL__QUEUE_CONFIGURATION:
				setQueueConfiguration((QueueingConfigurationModel)null);
				return;
			case NetmodelPackage.NETWORK_CONFIGURATION_MODEL__MESSAGE_FLOWS:
				getMessageFlows().clear();
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case NetmodelPackage.NETWORK_CONFIGURATION_MODEL__NODES:
				return nodes != null && !nodes.isEmpty();
			case NetmodelPackage.NETWORK_CONFIGURATION_MODEL__LINKS:
				return links != null && !links.isEmpty();
			case NetmodelPackage.NETWORK_CONFIGURATION_MODEL__DISTRIBUTIONS:
				return distributions != null && !distributions.isEmpty();
			case NetmodelPackage.NETWORK_CONFIGURATION_MODEL__QUEUE_CONFIGURATION:
				return queueConfiguration != null;
			case NetmodelPackage.NETWORK_CONFIGURATION_MODEL__MESSAGE_FLOWS:
				return messageFlows != null && !messageFlows.isEmpty();
		}
		return super.eIsSet(featureID);
	}

	/**
	 * @generated not
	 */
	@Override
	public SimulationContext getSimulationContext() {
		return simulationContext;
	}
	
	/**
	 * @generated not
	 */
	private SimulationContext simulationContext = null;
	
	/**
	 * @generated not
	 */
	public void setSimulationContext(SimulationContext info) {
		this.simulationContext = info;
	}
	
	/**
	 * @generated not
	 */
	String decoratorId;
	
	/**
	 * @generated not
	 */
	public String getDecoratorId() {
		return decoratorId;
	}
	
	/**
	 * @generated not
	 * @param id
	 */
	public void setDecoratorId(String id) {
		this.decoratorId = id;
	}
} //NetworkConfigurationModelImpl
